package engine.tip.tipItem
{
	import engine.data.ModelLocator;
	import engine.data.ObjectData;
	import engine.data.RoleVo;
	import engine.flag.ResourcesPath;
	import engine.tip.TipsMainLogic;
	import engine.tip.TipsPanelUI;
	
	import newx.com.config.StaticIni;

	/**
	 * 基础类
	 * @author yanghr
	 * 
	 */
	public class BaseTipItem implements ITipItem
	{
		/**
		 * 0,
		 * 1,白
		 * 2.绿
		 * 3.蓝
		 * 4.紫红
		 * 5.橙黄
		 * 6.黄
		 * 7.浅黄
		 */		
		protected const COLOR_TABLE	:Array	=	["","#ffffff'>","#1eff00'>","#20BFF8'>","#a335ee'>","#E8912E'>","#e5cc80'>","#ffff00'>"];
		/**
		 * //		case 0:  //铜钱
//		strID ="UIString_1000240"
//		break;
//		case 1: //阅历
//		strID ="UIString_1000241"
//		break;
//		case 2:  //江湖声望
//		strID ="UIString_1000242"
//		break;
//		case 3:  //修为
//		strID ="UIString_1000243"
//		break;
//		case 4: //元宝
//		strID ="UIString_1000244" 
 * 
 * //2
 * 
 * 	CAPITAL_TYPE_UNKNOWN	= 0,	// 未定义类型
	CAPITAL_TYPE_WHITE		= 1,	// 白玉牌
	CAPITAL_TYPE_GREEN		= 2,	// 绿玉牌
	CAPITAL_TYPE_BLUE		= 3,	// 蓝玉牌
	CAPITAL_TYPE_PUEPLE		= 4,	// 紫玉牌
	CAPITAL_TYPE_YELLOW		= 5,	// 黄玉牌
		 */		
		protected const SALE_TYPE:Array=[
			[],
			["UIString_1000240","UIString_1000241","UIString_1000242","UIString_1000243","UIString_1000244"],
			["","UIString_1000245","UIString_1000246","UIString_1000247","UIString_1000248","UIString_1000249","33020006"]
		]
//		case 1:   //白
//		strID ="UIString_1000245"
//		break;
//		case 2:   //绿
//		strID ="UIString_1000246"
//		break;
//		case 3: //蓝
//		strID ="UIString_1000247"
//		break;
//		case 4:   //紫
//		strID ="UIString_1000248"
//		break;
//		case 5:  //黄
//		strID ="UIString_1000249"
//		break;

		protected var _dataObj:ObjectData;
		protected var _panel:TipsPanelUI;
		protected var _data:Object;
		private var _model:String="";
		protected var _role:RoleVo;
		/**
		 *图片model 
		 * @return 
		 * 
		 */		
		public function get model():String
		{
			_model = _data["Photo"];
			if (!_model)
			{
				_model	=	_data["model"]
			}
			return _model;
		}
		public function BaseTipItem(dataObject:ObjectData=null,data:Object=null)
		{
			if(dataObject)
				dataObj=dataObject;
			if(data)
				_data=data;
			
			_role=ModelLocator.getInstance().scene.Role;
		
		}
		
		/**
		 *合并之后的obj 
		 */
		public function get data():Object
		{
			return _data;
		}

		/**
		 * @private
		 */
		public function set data(value:Object):void
		{
			_data = value;
		}

		public function set dataObj(value:ObjectData):void
		{
			_dataObj	=	value;
			if(_dataObj)
				_data=combiObj(_dataObj);
		}
		/**
		 *返回tips显示所需的一切字符串 
		 * @return 
		 * 
		 */		
		public function getMainStr():String
		{
			return "";
		}
		
		public function set panel(value:TipsPanelUI):void
		{
			// TODO Auto Generated method stub
			_panel=value;
			
		}
		
		public function buildTip():void
		{
			setPic();
//			trace(getMainStr());
			_panel.addText(getMainStr());
		}
		/**
		 *合并obj 
		 * @param objdata
		 * @return 
		 * 
		 */		
		public function combiObj(objdata:ObjectData):Object
		{
			var obj:Object = getConfigIdObj(objdata.GetPropertiesEx("ConfigID"));
			var property : String;
			
			for ( property in objdata.Properties)
			{
				obj[ property ] = objdata.GetPropertiesEx(property);
			}
			return obj;
		}
		/**
		 *得到配置obj 
		 * @param view
		 * @return 
		 * 
		 */	
		public function getConfigIdObj(id:String):Object
		{
			if(id)
			{
				var obj:Object= StaticIni.getIniObj(id);
				if(!obj)return null;
				var newObj:Object=new Object();
				for  (var i:String in obj) 
				{
					newObj[i]=obj[i];
				}
				return newObj;
			}
			return null;
		}
			
		/**
		 *设置显示图片 
		 * 
		 */		
		protected function setPic():void
		{
			var  obj:Object=_dataObj?_dataObj.Properties:_data
			if(!obj)	return;
			if(!model) return;
			_panel.addPicFree(ResourcesPath.getPropsURL(int(model)),160,10);
		}
		protected function link_color(str:String,color:int):String
		{
			if(color < 1 || color >8)
			{
				color	=	1;
			}
			return ("<font color ='"+COLOR_TABLE[color]+str+"</font>");
		}
		/**
		 *	名字 
		 * @return 
		 * 
		 */	
		public function getName():String
		{
			return StaticIni.getSwfLangStrVar("Tips_name",[link_color(getNormalName(),_data["Color"])]);
//			return StaticIni.getSwfLangStr(_dataObj.GetPropertiesEx("ConfigID"));
		}
		/**
		 *加一根线 
		 * @return 
		 * 
		 */		
		public function getALine():String
		{
			return 	_panel.addLinePic()+getChangeLine()
		}
		public function getNormalName():String
		{
			if(_dataObj	&&	_dataObj==ModelLocator.getInstance().scene.Role)
			{
					return _dataObj.GetPropertiesEx("Name");
			}
			if(_data)
			{
				return StaticIni.getSwfLangStr(_data["ConfigID"])
			}
			else if(_dataObj)
			{
				return StaticIni.getSwfLangStr(_dataObj.GetPropertiesEx("ConfigID"))
			}
			else
			{
				return "没名字可以不~"
			}
			
		}
		public function getColorHtml(str:String,color:String="f00000"):String
		{
			return "<font color='#" + color + "'>" + str + "</font>";
		}
		/**
		 *描述 
		 * @return 
		 * 
		 */		
		public function getDescribe():String
		{
//			var des:String		=	_data["Description"];
			var str:String	=	""
//			if(des != null && des != "")
//			{
				str			= 	StaticIni.getSwfLangStr("Description_"+_data.ConfigID);
//			}
			if(str)
				return str	+	getChangeLine();
			return ""
		}
		/**
		 *得到售价 
		 * @return 
		 * 
		 */		
		public function getPrice():String
		{
			//				var sellPrice:String	= StaticIni.getIniVar(configID,"SellPrice");
			//				str = str.concat("<br>");
			//				str = str.concat(StaticIni.getSwfLangStr("UIStr_1000296"));
			//				str = str.concat(sellPrice);
			
			var str:String = "";
			//卖只能获得金币
			var sellPrice:String		= _data.SellValue;
			var type:int=data["_type"];
			var kind:int=data["_kind"];
			if(!type)
			{
				if(int(sellPrice) > 0)
				{
					str = str.concat(StaticIni.getSwfLangStr("UIStr_1000296"));
					str = str.concat(sellPrice);
					str = str.concat(StaticIni.getSwfLangStr("Tips_CapitalType0"));
				}
			}
			else
			{
				str	=StaticIni.getSwfLangStr("UIString_1000320")+"  "+sellPrice+StaticIni.getSwfLangStr(SALE_TYPE[type][kind]);
			}
			str=TipsMainLogic.instance.getColorHtml(str,"E1D28E")
			return str
		}
		/**
		 *得到通常属性颜色 
		 * @param propertyStr
		 * @return 
		 * 
		 */		
		protected function getPropertyColor(propertyStr:String):String
		{
			return TipsMainLogic.instance.getColorHtml(propertyStr,"E8912E");
		}
		/**
		 *取属性 简约方法 
		 * @param index
		 * @return 
		 * 
		 */		
		protected function getSingleProperty(index:int):String
		{
			var tips:String	=	"";
			var property:String	= _data["AddPropNo"+index];
			if(property != null && property != "" && property != "0")
			{
				var color:int=_data["Color"];
				tips 	=	con(StaticIni.getSwfLangStrVar("Item_" +property.substr(0,3),[ property.substr(4) ]));
			}
			
			return tips;
			function con(str:String):String
			{
				return tips.concat(link_color(str, color));
			}
		}
		/**
		 *换行符 
		 * @return 
		 * 
		 */		
		public function getChangeLine():String
		{
			return "<br>"
		}
		public function get configId():*
		{
			return data["ConfigID"];
		}
		
	}
}